function dPjdvk = grad_dPdv2(y,dudv,H,impossible,j,phi,s,u)

x = y./phi + u;
Lambda = exp(-exp(-x(1:end-1)));
Lambda(impossible(1:end-1)) = 1;
F = 1 - exp(-s*x(end));
f = s*exp(-s*x(end));
summand = repmat(exp(-x(1:end-1)),[1,H-1]).*dudv(1:end-1,:);
summand(repmat(impossible(1:end-1),[1,H-1])) = 0;

if j < H+1  
    
    dPjdvk = (sum(summand)*F + dudv(end,:)*f - F*dudv(j-1,:))*prod(Lambda)...
        *exp(-x(j-1))*1/phi(j-1);
else

    dPjdvk = prod(Lambda)*(sum(summand)*f - dudv(end,:)*s^2*exp(-s*x(end)));   
end